package search;

import java.sql.SQLException;
import java.util.List;

public class SearchOfFav implements Search{
    SearchMQL searchMQL=new SearchMQL();
    String sql;

    public SearchOfFav(){}

    @Override
    public List<Recipe> searchAll() throws SQLException {

        sql="SELECT * \n" +
                "FROM recipes \n" +
                "JOIN recipe_popular_filters \n" +
                "ON recipes.recipe_id = recipe_popular_filters.recipe_id \n" +
                "ORDER BY recipe_popular_filters.popularity_level DESC;\n";
        return searchMQL.mysqlSearch(sql);
    }

    @Override
    public List<Recipe> recipes(String keyword) throws SQLException {
        if(keyword.length()>2) {
            sql = "SELECT * FROM recipes WHERE MATCH(recipe_name) AGAINST('" + keyword + "' IN BOOLEAN MODE)";
        }else {
            sql = "SELECT * FROM recipes WHERE recipe_name LIKE '%"+keyword+"%'";
        }
        return searchMQL.mysqlSearch(sql);
    }
}
